package org.dromara.nursing.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.nursing.domain.vo.MsServiceQualityStatisticsVo;
import org.dromara.nursing.domain.bo.MsServiceQualityStatisticsBo;
import org.dromara.nursing.service.IMsServiceQualityStatisticsService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 服务质量统计
 *
 * @author Lion Li
 * @date 2025-04-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/nursing/serviceQualityStatistics")
public class MsServiceQualityStatisticsController extends BaseController {

    private final IMsServiceQualityStatisticsService msServiceQualityStatisticsService;

    /**
     * 查询服务质量统计列表
     */
    // @SaCheckPermission("nursing:serviceQualityStatistics:list")
    @GetMapping("/list")
    public TableDataInfo<MsServiceQualityStatisticsVo> list(MsServiceQualityStatisticsBo bo, PageQuery pageQuery) {
        return msServiceQualityStatisticsService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出服务质量统计列表
     */
    // @SaCheckPermission("nursing:serviceQualityStatistics:export")
    @Log(title = "服务质量统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(MsServiceQualityStatisticsBo bo, HttpServletResponse response) {
        List<MsServiceQualityStatisticsVo> list = msServiceQualityStatisticsService.queryList(bo);
        ExcelUtil.exportExcel(list, "服务质量统计", MsServiceQualityStatisticsVo.class, response);
    }

    /**
     * 获取服务质量统计详细信息
     *
     * @param statId 主键
     */
    // @SaCheckPermission("nursing:serviceQualityStatistics:query")
    @GetMapping("/{statId}")
    public R<MsServiceQualityStatisticsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long statId) {
        return R.ok(msServiceQualityStatisticsService.queryById(statId));
    }

    /**
     * 新增服务质量统计
     */
    // @SaCheckPermission("nursing:serviceQualityStatistics:add")
    @Log(title = "服务质量统计", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody MsServiceQualityStatisticsBo bo) {
        return toAjax(msServiceQualityStatisticsService.insertByBo(bo));
    }

    /**
     * 修改服务质量统计
     */
    // @SaCheckPermission("nursing:serviceQualityStatistics:edit")
    @Log(title = "服务质量统计", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody MsServiceQualityStatisticsBo bo) {
        return toAjax(msServiceQualityStatisticsService.updateByBo(bo));
    }

    /**
     * 删除服务质量统计
     *
     * @param statIds 主键串
     */
    // @SaCheckPermission("nursing:serviceQualityStatistics:remove")
    @Log(title = "服务质量统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{statIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] statIds) {
        return toAjax(msServiceQualityStatisticsService.deleteWithValidByIds(List.of(statIds), true));
    }
}
